<?
session_start();
//session_register('kart_array');
$path = '../Mkart/';
include($path."common.php");
include($path."prod_fun.php");

//$_SESSION['kart_array'] = $_SESSION['kart_array'] ;
$id = $_GET['pid'] ;

if($id <> ""){
$sql = "select * from product where id = '$id' order by id" ;
$result = mysql_query($sql) ;
$row = mysql_fetch_object($result) ;
$pord_name = $row -> name ;
$price = $row -> price_2 ;
$qty = $row -> pd_count ;

if($_SESSION['kart_array'] <> ""){
$check_id = chk_array('id',$id,$_SESSION['kart_array']) ;
}

if($check_id == "Y"){
$prod_count = arr_search($_SESSION['kart_array'],"id==$id") ;
if($prod_count[0]["count"] < 100 and $prod_count[0]["count"] < $qty){
$count = $prod_count[0]["count"] + 1 ;
}else{
$count = $prod_count[0]["count"] ;
}
$price_total = $price * $count ; 
$_SESSION['kart_array'] = del_array('id',$id,$_SESSION['kart_array']) ;
$_SESSION['kart_array'][] = array("id"=>$id,"name"=>$pord_name,"price"=>$price_total,"count"=>$count);

}else{
$count  = 1 ;
$_SESSION['kart_array'][] = array("id"=>$id,"name"=>$pord_name,"price"=>$price,"count"=>$count);
}


$kart_table  .= "<table width=100% border=1>" ;
for($i=0;$i<count($_SESSION['kart_array']);$i++){
$kart_table  .= "<tr>" ;
//$kart_table  .= "<td>".$_SESSION['kart_array'][$i]["id"]."</td>" ;
$kart_table  .= "<td>"."$".$_SESSION['kart_array'][$i]["price"]."</td>" ;
$kart_table  .= "<td>".$_SESSION['kart_array'][$i]["count"]."</td>" ;
$kart_table  .= "</tr>" ;
}
$price_sum  = count_array('price',$_SESSION['kart_array']) ;
$count_sum  = count_array('count',$_SESSION['kart_array']) ;
$kart_table  .= "<tr>" ;
$kart_table  .= "<td><font color=red>"."$".$price_sum."</font></td>" ;
$kart_table  .= "<td><font color=red>".$count_sum."</font></td>" ;
$kart_table  .= "</tr>" ;
$kart_table  .= "</table>" ;

}elseif($id == "" and $_SESSION['kart_array'] <> ""){
$kart_table  .= "<table width=100% border=1>" ;
for($i=0;$i<count($_SESSION['kart_array']);$i++){
$kart_table  .= "<tr>" ;
//$kart_table  .= "<td>".$_SESSION['kart_array'][$i]["id"]."</td>" ;
$kart_table  .= "<td>"."$".$_SESSION['kart_array'][$i]["price"]."</td>" ;
$kart_table  .= "<td>".$_SESSION['kart_array'][$i]["count"]."</td>" ;
$kart_table  .= "</tr>" ;
}
$price_sum  = count_array('price',$_SESSION['kart_array']) ;
$count_sum  = count_array('count',$_SESSION['kart_array']) ;
$kart_table  .= "<tr>" ;
$kart_table  .= "<td><font color=red>"."$".$price_sum."</font></td>" ;
$kart_table  .= "<td><font color=red>".$count_sum."</font></td>" ;
$kart_table  .= "</tr>" ;
//$kart_table  .= "<tr>" ;
//$kart_table  .= "<td colspan=2>"."$".$price_sum."</font></td>" ;
//$kart_table  .= "</tr>" ;
$kart_table  .= "</table>" ;
}else{
$_SESSION['kart_array'] = "" ;
$kart_table  .= "<table width=100% border=0>" ;
$kart_table  .= "<tr>" ;
$kart_table  .= "<td></td>" ;
$kart_table  .= "</tr>" ;
$kart_table  .= "</table>" ;
}
echo $kart_table ;
//print_r($_SESSION['kart_array']) ;

?>